package com.slipper.codeless.resolve;

import com.slipper.codeless.resolve.delete.Delete;
import com.slipper.codeless.resolve.query.Query;
import com.slipper.codeless.resolve.support.MysqlSqlBuilder;
import com.slipper.codeless.resolve.support.PostgresqlSqlBuilder;
import com.slipper.codeless.resolve.support.SqlserverSqlBuilder;
import com.slipper.codeless.resolve.update.Update;
import com.slipper.util.DatabaseUtil;

import static com.slipper.constants.Constants.Database.*;

import java.util.HashMap;
import java.util.Map;

public class SqlBuilderFactory {
    private static final Map<String, ISqlBuilder> sqlBuilderMap = new HashMap<>() {{
        put(MYSQL, new MysqlSqlBuilder());
        put(POSTGRESQL, new PostgresqlSqlBuilder());
        put(SQLSERVER, new SqlserverSqlBuilder());
    }};

    public static Map<String, Object> buildQueryMap(Query query) {
        return buildQueryMap(DatabaseUtil.getType(), query);
    }

    public static Map<String, Object> buildQueryMap(String dbType, Query query) {
        return sqlBuilderMap.get(dbType.toLowerCase()).buildQueryMap(query);
    }

    public static Map<String, Object> buildUpdateMap(Update update) {
        return buildUpdateMap(DatabaseUtil.getType(), update);
    }

    public static Map<String, Object> buildUpdateMap(String dbType, Update update) {
        return sqlBuilderMap.get(dbType.toLowerCase()).buildUpdateMap(update);
    }

    public static Map<String, Object> buildDeleteMap(Delete delete) {
        return buildDeleteMap(DatabaseUtil.getType(), delete);
    }

    public static Map<String, Object> buildDeleteMap(String dbType, Delete delete) {
        return sqlBuilderMap.get(dbType.toLowerCase()).buildDeleteMap(delete);
    }
}
